/**
 * 项目设置 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-12 10:58:48
 */
layui.use(['jquery','febs', 'commonJS','form','formSelects', 'laydate','validate'], function () {
       var $ = layui.$,
        febs = layui.febs,
        commonJS = layui.commonJS,
        layer = layui.layer,
        form = layui.form,
        formSelects = layui.formSelects,
        $view = $('#sypqProject-edit'),
        $auditOperator = $view.find('#auditOperator'),
        $submit=$view.find("#submit"),
        $reset=$view.find("#reset"),
        validate = layui.validate;
       formSelects.render();
       form.verify(validate);
        form.render();
        initFormValue();
        initTable();
        setAuditDisplay();

      function  setAuditDisplay(){
            if(typeData=='detail'){
                $auditOperator.css("display", 'none');
                $submit.css("display","none");
            }else if(typeData=='audit'){
                $auditOperator.css("display", 'block');
                $submit.css("display","inline-block");
                form.render();
            }
        }


    function initTable() {
        tableIns = febs.table.init({
            elem: $view.find('table'),
            id: 'workfloswRecordTable',
            url: ctx + 'workflowRecord/list',
            page: false,
            loading: false,
            where: getQueryParams(),
            height: getTableHeight()/5,
            skin: '',
            cols: [[
                {field: 'remark', title: '操作', minWidth: 80},
                {field: 'createdTime', title: '时间', minWidth: 150},
            ]],
            //  toolbar: '#sypqProject-toolbar',
            defaultToolbar: []
        });
    }


    function getQueryParams() {
        return {
            voucherId: sypqProjectData.projectCode,
            voucherType: 5,
            invalidate_ie_cache: new Date()
        };
    }

    function getTableHeight() {
        return commonJS.calcTableHeight();
    }


    function initFormValue() {
        if (sypqProjectData) {
            form.val("sypqProject-edit-form", {
                "projectCode": sypqProjectData.projectCode,
                "projectName": sypqProjectData.projectName,
                "managers": sypqProjectData.managers,
                "auditor": sypqProjectData.auditor,
                "custCode": sypqProjectData.custCode,
                "custName": sypqProjectData.custName,
                "contact": sypqProjectData.contact,
                "telephone": sypqProjectData.telephone,
                "status": sypqProjectData.status,
                "testDemand": sypqProjectData.testDemand,
                "expectStartdate": sypqProjectData.expectStartdate,
                "expectEnddate": sypqProjectData.expectEnddate,
                "planStartdate": sypqProjectData.planStartdate,
                "planEnddate": sypqProjectData.planEnddate,
                "actualStartdate": sypqProjectData.actualStartdate,
                "actualEnddate": sypqProjectData.actualEnddate,
                "createdTime": sypqProjectData.createdTime,
                "deletedFlg": sypqProjectData.deletedFlg,
                "approveStatus": sypqProjectData.approveStatus,
            });
        }
    }


    form.on('submit(sypqProject-edit-form-submit)', function (data) {
        data.field.voucherId=data.field.projectCode;
        var  status=data.field.auditStatus;
        data.field.status=status;
        if(status=='3'&&data.field.remark==''){
            febs.alert.warn('审批不通过时,请说明原因');
            return ;
        }
        febs.modal.confirm("提交提示！", "是否提交？", function (index) {
            febs.postArray(ctx + 'sypqProject/saveAudit', data.field, function () {
                layer.closeAll();
                febs.alert.success('审核成功');
                var currentUrl = window.location.hash.replace('#', '');
                febs.view.tab.del(currentUrl);
                febs.view.tab.change("/sypqProject");
                $('#febs-sypqProject').find('#query').trigger('click');
            });
        });

        return false;
    });

    $('#reset').click(function () {
        closeCur();
    });

    function closeCur(){
        var currentUrl = window.location.hash.replace('#', '');
        febs.view.tab.del(currentUrl);
        febs.view.tab.change("/sypqProject");
        $('#febs-sypqProject').find('#query').trigger('click');
    }



});